#include<iostream>
#include<string>
using namespace std;
typedef long long LL;
string x;
LL b=0;
LL gcd(LL a,LL b)
{
    if(b==0) return a;
    else
    {
        return gcd(b,a%b);
    }
}
LL calc()
{
    LL t=0;
    for(auto e:x)
    {
        t=t*10+e-'0';
        t%=b;//运用模运算的分配性质
    }
    return t;
}
int main()
{
    cin>>x>>b;
    cout<<gcd(b,calc())<<endl;
    return 0;
}